// $ANTLR 3.1.1 iLPMED.g 2009-10-05 23:27:33
// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 168, 219
// Unreachable code detected.
#pragma warning disable 162
namespace  Core.ANTLRGrammars 
{

using System;
using Antlr.Runtime;
using IList 		= System.Collections.IList;
using ArrayList 	= System.Collections.ArrayList;
using Stack 		= Antlr.Runtime.Collections.StackList;



using Antlr.Runtime.Tree;

/***************************************************************
****************************************************************
****************** Parser for Interpreted LPMED ****************
****************************************************************
***************************************************************/
public partial class iLPMED : Parser
{
    public static readonly string[] tokenNames = new string[] 
	{
        "<invalid>", 
		"<EOR>", 
		"<DOWN>", 
		"<UP>", 
		"CPROGRAM", 
		"CDEVICE", 
		"CTYPE", 
		"CBLOCK", 
		"CSTATEMENT", 
		"CIFTE", 
		"CASSIGN", 
		"CWHILE", 
		"CFOR", 
		"CFORDEC", 
		"CUNARMIN", 
		"CMETHODNAME", 
		"CCALL", 
		"CINT", 
		"CFLOAT", 
		"CBOOL", 
		"CSYNCCALL", 
		"CASYNCCALL", 
		"CWAITTHECALL", 
		"CWAITANYCALL", 
		"CENDTHECALL", 
		"OBJECTNAME", 
		"MEMBERNAME", 
		"NODES", 
		"CGETSTATE", 
		"CBREAKPOINT", 
		"CREGMETHACCESS", 
		"CREGFUNCACCESS", 
		"CTERMINATEALL", 
		"CASYNCFUNCCALL", 
		"CSYNCFUNCCALL", 
		"CWAITFUNCFINISH", 
		"CDEFUN", 
		"PARAMS", 
		"PARAM", 
		"TERMINATEALL", 
		"OpIncDec", 
		"OpNegation", 
		"OpUnar", 
		"OpDivMul", 
		"OpAddSub", 
		"OpLogicalA", 
		"OpLogicalB", 
		"OpAnd", 
		"OpOr", 
		"TYPE", 
		"DBOOL", 
		"DEVICE", 
		"STATE", 
		"ENDDEVICE", 
		"INT", 
		"FLOAT", 
		"IF", 
		"THEN", 
		"ELSE", 
		"FOR", 
		"WHILE", 
		"WAIT", 
		"GO", 
		"ENDPRESSURE", 
		"VAR", 
		"BREAKPOINT", 
		"DEFUN", 
		"WS", 
		"NEWLINE", 
		"LINECOMMENT", 
		"ID", 
		"OBRACKET", 
		"CBRACKET", 
		"CURLYOBRACKET", 
		"CURLYCBRACKET", 
		"EQUALS", 
		"DOT", 
		"SEMI", 
		"COLON", 
		"COMMA", 
		"80", 
		"81", 
		"82", 
		"83", 
		"84", 
		"85", 
		"86", 
		"87", 
		"88", 
		"89", 
		"90", 
		"91", 
		"92", 
		"93", 
		"94", 
		"95", 
		"96", 
		"97", 
		"98", 
		"99", 
		"100", 
		"101", 
		"102", 
		"103", 
		"104", 
		"105", 
		"106", 
		"107", 
		"108", 
		"109", 
		"110", 
		"111", 
		"112", 
		"113"
    };

    public const int OpIncDec = 40;
    public const int WHILE = 60;
    public const int OpLogicalA = 45;
    public const int OBJECTNAME = 25;
    public const int OpAnd = 47;
    public const int CPROGRAM = 4;
    public const int OpLogicalB = 46;
    public const int OpNegation = 41;
    public const int CTYPE = 6;
    public const int DBOOL = 50;
    public const int FOR = 59;
    public const int PARAM = 38;
    public const int FLOAT = 55;
    public const int EQUALS = 75;
    public const int OpAddSub = 44;
    public const int CURLYCBRACKET = 74;
    public const int LINECOMMENT = 69;
    public const int ID = 70;
    public const int EOF = -1;
    public const int CASYNCCALL = 21;
    public const int CSYNCFUNCCALL = 34;
    public const int IF = 56;
    public const int TYPE = 49;
    public const int CIFTE = 9;
    public const int CWAITANYCALL = 23;
    public const int CWAITFUNCFINISH = 35;
    public const int THEN = 57;
    public const int CFORDEC = 13;
    public const int COMMA = 79;
    public const int OpDivMul = 43;
    public const int CDEVICE = 5;
    public const int CURLYOBRACKET = 73;
    public const int CSYNCCALL = 20;
    public const int CFOR = 12;
    public const int DEVICE = 51;
    public const int NODES = 27;
    public const int VAR = 64;
    public const int CREGFUNCACCESS = 31;
    public const int ENDDEVICE = 53;
    public const int DOT = 76;
    public const int CMETHODNAME = 15;
    public const int CBRACKET = 72;
    public const int PARAMS = 37;
    public const int MEMBERNAME = 26;
    public const int CWHILE = 11;
    public const int STATE = 52;
    public const int DEFUN = 66;
    public const int OpUnar = 42;
    public const int CTERMINATEALL = 32;
    public const int CREGMETHACCESS = 30;
    public const int ELSE = 58;
    public const int CDEFUN = 36;
    public const int CSTATEMENT = 8;
    public const int CUNARMIN = 14;
    public const int INT = 54;
    public const int WAIT = 61;
    public const int SEMI = 77;
    public const int CASSIGN = 10;
    public const int COLON = 78;
    public const int CBREAKPOINT = 29;
    public const int CINT = 17;
    public const int WS = 67;
    public const int TERMINATEALL = 39;
    public const int CENDTHECALL = 24;
    public const int NEWLINE = 68;
    public const int OpOr = 48;
    public const int ENDPRESSURE = 63;
    public const int CBLOCK = 7;
    public const int CCALL = 16;
    public const int CASYNCFUNCCALL = 33;
    public const int CGETSTATE = 28;
    public const int GO = 62;
    public const int OBRACKET = 71;
    public const int CBOOL = 19;
    public const int CFLOAT = 18;
    public const int BREAKPOINT = 65;
    public const int CWAITTHECALL = 22;

    // delegates
    public iLPMED_LPMEDParser gLPMEDParser;
    // delegators



        public iLPMED(ITokenStream input)
    		: this(input, new RecognizerSharedState()) {
        }

        public iLPMED(ITokenStream input, RecognizerSharedState state)
    		: base(input, state) {
            InitializeCyclicDFAs();

            gLPMEDParser = new iLPMED_LPMEDParser(input, state, this);         
        }
        
    protected ITreeAdaptor adaptor = new CommonTreeAdaptor();

    public ITreeAdaptor TreeAdaptor
    {
        get { return this.adaptor; }
        set {
    	this.adaptor = value;
    	gLPMEDParser.TreeAdaptor = this.adaptor;
    	}
    }

    override public string[] TokenNames {
		get { return iLPMED.tokenNames; }
    }

    override public string GrammarFileName {
		get { return "iLPMED.g"; }
    }


    	public System.Collections.Generic.List<Exception> Logger = new System.Collections.Generic.List<Exception>();


    public class program_return : ParserRuleReturnScope
    {
        private CommonTree tree;
        override public object Tree
        {
        	get { return tree; }
        	set { tree = (CommonTree) value; }
        }
    };

    // $ANTLR start "program"
    // iLPMED.g:31:1: program : (stmts+= stmt | decls+= varDecListFree )* -> ^( CPROGRAM ( $decls)* ^( CSTATEMENT ( $stmts)* ) ) ;
    public iLPMED.program_return program() // throws RecognitionException [1]
    {   
        iLPMED.program_return retval = new iLPMED.program_return();
        retval.Start = input.LT(1);

        CommonTree root_0 = null;

        IList list_stmts = null;
        IList list_decls = null;
        RuleReturnScope stmts = null;
        RuleReturnScope decls = null;
        RewriteRuleSubtreeStream stream_varDecListFree = new RewriteRuleSubtreeStream(adaptor,"rule varDecListFree");
        RewriteRuleSubtreeStream stream_stmt = new RewriteRuleSubtreeStream(adaptor,"rule stmt");
        try 
    	{
            // iLPMED.g:32:1: ( (stmts+= stmt | decls+= varDecListFree )* -> ^( CPROGRAM ( $decls)* ^( CSTATEMENT ( $stmts)* ) ) )
            // iLPMED.g:33:2: (stmts+= stmt | decls+= varDecListFree )*
            {
            	// iLPMED.g:33:2: (stmts+= stmt | decls+= varDecListFree )*
            	do 
            	{
            	    int alt1 = 3;
            	    int LA1_0 = input.LA(1);

            	    if ( (LA1_0 == TERMINATEALL || LA1_0 == IF || (LA1_0 >= FOR && LA1_0 <= WHILE) || (LA1_0 >= BREAKPOINT && LA1_0 <= DEFUN) || LA1_0 == ID || LA1_0 == CURLYOBRACKET) )
            	    {
            	        alt1 = 1;
            	    }
            	    else if ( (LA1_0 == VAR) )
            	    {
            	        alt1 = 2;
            	    }


            	    switch (alt1) 
            		{
            			case 1 :
            			    // iLPMED.g:33:3: stmts+= stmt
            			    {
            			    	PushFollow(FOLLOW_stmt_in_program80);
            			    	stmts = stmt();
            			    	state.followingStackPointer--;

            			    	stream_stmt.Add(stmts.Tree);
            			    	if (list_stmts == null) list_stmts = new ArrayList();
            			    	list_stmts.Add(stmts.Tree);


            			    }
            			    break;
            			case 2 :
            			    // iLPMED.g:33:19: decls+= varDecListFree
            			    {
            			    	PushFollow(FOLLOW_varDecListFree_in_program88);
            			    	decls = varDecListFree();
            			    	state.followingStackPointer--;

            			    	stream_varDecListFree.Add(decls.Tree);
            			    	if (list_decls == null) list_decls = new ArrayList();
            			    	list_decls.Add(decls.Tree);


            			    }
            			    break;

            			default:
            			    goto loop1;
            	    }
            	} while (true);

            	loop1:
            		;	// Stops C# compiler whining that label 'loop1' has no statements



            	// AST REWRITE
            	// elements:          decls, stmts
            	// token labels:      
            	// rule labels:       retval
            	// token list labels: 
            	// rule list labels:  stmts, decls
            	retval.Tree = root_0;
            	RewriteRuleSubtreeStream stream_retval = new RewriteRuleSubtreeStream(adaptor, "token retval", (retval!=null ? retval.Tree : null));
            	RewriteRuleSubtreeStream stream_stmts = new RewriteRuleSubtreeStream(adaptor, "token stmts", list_stmts);
            	RewriteRuleSubtreeStream stream_decls = new RewriteRuleSubtreeStream(adaptor, "token decls", list_decls);
            	root_0 = (CommonTree)adaptor.GetNilNode();
            	// 33:45: -> ^( CPROGRAM ( $decls)* ^( CSTATEMENT ( $stmts)* ) )
            	{
            	    // iLPMED.g:33:48: ^( CPROGRAM ( $decls)* ^( CSTATEMENT ( $stmts)* ) )
            	    {
            	    CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
            	    root_1 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(CPROGRAM, "CPROGRAM"), root_1);

            	    // iLPMED.g:33:59: ( $decls)*
            	    while ( stream_decls.HasNext() )
            	    {
            	        adaptor.AddChild(root_1, stream_decls.NextTree());

            	    }
            	    stream_decls.Reset();
            	    // iLPMED.g:33:67: ^( CSTATEMENT ( $stmts)* )
            	    {
            	    CommonTree root_2 = (CommonTree)adaptor.GetNilNode();
            	    root_2 = (CommonTree)adaptor.BecomeRoot((CommonTree)adaptor.Create(CSTATEMENT, "CSTATEMENT"), root_2);

            	    // iLPMED.g:33:80: ( $stmts)*
            	    while ( stream_stmts.HasNext() )
            	    {
            	        adaptor.AddChild(root_2, stream_stmts.NextTree());

            	    }
            	    stream_stmts.Reset();

            	    adaptor.AddChild(root_1, root_2);
            	    }

            	    adaptor.AddChild(root_0, root_1);
            	    }

            	}

            	retval.Tree = root_0;retval.Tree = root_0;
            }

            retval.Stop = input.LT(-1);

            	retval.Tree = (CommonTree)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);
        }
        catch (Exception e) 
        {
            Logger.Add(e); if (e is RecognitionException) Recover(input,(RecognitionException)e);
        }
        finally 
    	{
        }
        return retval;
    }
    // $ANTLR end "program"

    // Delegated rules
        public iLPMED_LPMEDParser.varDecListFree_return varDecListFree() // throws RecognitionException 
        {
    return gLPMEDParser.varDecListFree(); 
        }
        public iLPMED_LPMEDParser.peremDecList_return peremDecList() // throws RecognitionException 
        {
    return gLPMEDParser.peremDecList(); 
        }
        public iLPMED_LPMEDParser.ifStmt_return ifStmt() // throws RecognitionException 
        {
    return gLPMEDParser.ifStmt(); 
        }
        public iLPMED_LPMEDParser.functionBody_return functionBody() // throws RecognitionException 
        {
    return gLPMEDParser.functionBody(); 
        }
        public iLPMED_LPMEDParser.functionDefinition_return functionDefinition() // throws RecognitionException 
        {
    return gLPMEDParser.functionDefinition(); 
        }
        public iLPMED_LPMEDParser.notExpr_return notExpr() // throws RecognitionException 
        {
    return gLPMEDParser.notExpr(); 
        }
        public iLPMED_LPMEDParser.parameterValue_return parameterValue() // throws RecognitionException 
        {
    return gLPMEDParser.parameterValue(); 
        }
        public iLPMED_LPMEDParser.assign_return assign() // throws RecognitionException 
        {
    return gLPMEDParser.assign(); 
        }
        public iLPMED_LPMEDParser.varDecListFixed_return varDecListFixed() // throws RecognitionException 
        {
    return gLPMEDParser.varDecListFixed(); 
        }
        public iLPMED_LPMEDParser.stmt_return stmt() // throws RecognitionException 
        {
    return gLPMEDParser.stmt(); 
        }
        public iLPMED_LPMEDParser.atom_return atom() // throws RecognitionException 
        {
    return gLPMEDParser.atom(); 
        }
        public iLPMED_LPMEDParser.varDecListAtom_return varDecListAtom() // throws RecognitionException 
        {
    return gLPMEDParser.varDecListAtom(); 
        }
        public iLPMED_LPMEDParser.andExpr_return andExpr() // throws RecognitionException 
        {
    return gLPMEDParser.andExpr(); 
        }
        public iLPMED_LPMEDParser.blockStmt_return blockStmt() // throws RecognitionException 
        {
    return gLPMEDParser.blockStmt(); 
        }
        public iLPMED_LPMEDParser.block_return block() // throws RecognitionException 
        {
    return gLPMEDParser.block(); 
        }
        public iLPMED_LPMEDParser.deviceMethodCall_return deviceMethodCall() // throws RecognitionException 
        {
    return gLPMEDParser.deviceMethodCall(); 
        }
        public iLPMED_LPMEDParser.parameter_return parameter() // throws RecognitionException 
        {
    return gLPMEDParser.parameter(); 
        }
        public iLPMED_LPMEDParser.parameterList_return parameterList() // throws RecognitionException 
        {
    return gLPMEDParser.parameterList(); 
        }
        public iLPMED_LPMEDParser.expr_return expr() // throws RecognitionException 
        {
    return gLPMEDParser.expr(); 
        }
        public iLPMED_LPMEDParser.functionCall_return functionCall() // throws RecognitionException 
        {
    return gLPMEDParser.functionCall(); 
        }
        public iLPMED_LPMEDParser.orExpr_return orExpr() // throws RecognitionException 
        {
    return gLPMEDParser.orExpr(); 
        }
        public iLPMED_LPMEDParser.multiplicativeExpr_return multiplicativeExpr() // throws RecognitionException 
        {
    return gLPMEDParser.multiplicativeExpr(); 
        }
        public iLPMED_LPMEDParser.functionSignature_return functionSignature() // throws RecognitionException 
        {
    return gLPMEDParser.functionSignature(); 
        }
        public iLPMED_LPMEDParser.deviceMemberID_return deviceMemberID() // throws RecognitionException 
        {
    return gLPMEDParser.deviceMemberID(); 
        }
        public iLPMED_LPMEDParser.primary_return primary() // throws RecognitionException 
        {
    return gLPMEDParser.primary(); 
        }
        public iLPMED_LPMEDParser.comparisonExpr_return comparisonExpr() // throws RecognitionException 
        {
    return gLPMEDParser.comparisonExpr(); 
        }
        public iLPMED_LPMEDParser.additiveExpr_return additiveExpr() // throws RecognitionException 
        {
    return gLPMEDParser.additiveExpr(); 
        }
        public iLPMED_LPMEDParser.equalityExpr_return equalityExpr() // throws RecognitionException 
        {
    return gLPMEDParser.equalityExpr(); 
        }
        public iLPMED_LPMEDParser.qualifiedName_return qualifiedName() // throws RecognitionException 
        {
    return gLPMEDParser.qualifiedName(); 
        }


	private void InitializeCyclicDFAs()
	{
	}

 

    public static readonly BitSet FOLLOW_stmt_in_program80 = new BitSet(new ulong[]{0x1900008000000002UL,0x0000000000000247UL});
    public static readonly BitSet FOLLOW_varDecListFree_in_program88 = new BitSet(new ulong[]{0x1900008000000002UL,0x0000000000000247UL});

}
}